package com.fourth_groups.shopping121store.ui.sight.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.fourth_groups.shopping121store.R;

public class WebActivity extends AppCompatActivity {

    private WebView mWv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_web);

        Intent intent=getIntent();
        String urlImg = intent.getStringExtra("urlImg");

        mWv = (WebView) findViewById(R.id.wv_sight);
        //对WebView进行设置
        WebSettings settings = mWv.getSettings();
        settings.setJavaScriptEnabled(true);//支持JavaScript脚步功能
        settings.setSupportZoom(true);//是否支持缩放
        settings.setDisplayZoomControls(true);//显示缩放
        //加载Url地址
        mWv.loadUrl(urlImg);
        //修改默认的浏览器
        mWv.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);//重新加载Url地址
                return super.shouldOverrideUrlLoading(view, url);
            }
        });

    }
    //        处理返回键
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        switch (keyCode){
            case KeyEvent.KEYCODE_BACK:
//  canGoBack可以返回到前一页
                if (mWv!=null&&mWv.canGoBack()){
                    mWv.goBack();//后退
                }else {finish();}
        }
//        return super.onKeyDown(keyCode, event);
        return false;
    }

}